package com.vlh.battleship.server.config;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource("classpath:/properties-config.xml")
public class DataSourceConfiguration {
	
	@Value("#{dataSourceConfig['jdbc.driver']}")
	private String driverClassName;

	@Value("#{dataSourceConfig['jdbc.url']}")
	private String driverUrl;

	@Value("#{dataSourceConfig['jdbc.user']}")
	private String driverUsername;

	@Value("#{dataSourceConfig['jdbc.password']}")
	private String driverPassword;

	@Bean
	public DataSource dataSource() {
		BasicDataSource dataSource = new BasicDataSource();
		dataSource.setDriverClassName(driverClassName);
		dataSource.setUrl(driverUrl);
		dataSource.setUsername(driverUsername);
		dataSource.setPassword(driverPassword);
		return dataSource;
	}
}
